package vip.xumy.admin.um.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import vip.xumy.admin.um.pojo.Permission;
import vip.xumy.admin.um.service.IPermissionService;
import vip.xumy.admin.um.service.IRolePermissionService;
import vip.xumy.admin.utils.LoginUtil;
import vip.xumy.core.exception.CoreException;
import vip.xumy.core.pojo.com.Entry;

/**
 * @author:mengyxu
 * @date:2019年10月21日
 */
@RestController
@RequestMapping("public")
public class PublicContoller {

	@Autowired
	private IRolePermissionService roleService;
	@Autowired
	private IPermissionService perService;

	@RequestMapping(value = "role/map", method = RequestMethod.GET)
	public List<Entry<String, String>> queryRoleMaps() {
		return roleService.queryRoleMaps();
	}

	@RequestMapping(value = "per/list", method = RequestMethod.GET)
	public List<Permission> queryPermissionTree(HttpServletRequest request) throws CoreException {
		return perService.queryPermissionTree(false);
	}

	@RequestMapping(value = "my/action/per")
	public List<String> queryMyActionPermissions(HttpServletRequest request) throws CoreException {
		String userName = LoginUtil.getUserId(request);
		String parentContent = LoginUtil.getParentContent(request);
		return perService.myPermissions(userName, parentContent);
	}

}
